#!/bin/bash

# IntelliJ IDEA 插件兼容性验证脚本

echo "🔍 验证 IntelliJ IDEA 插件兼容性..."
echo "=================================="

# 检查 Gradle 版本
echo "📋 检查 Gradle 版本..."
./gradlew --version

echo ""
echo "📋 检查插件配置..."

# 显示当前配置
echo "当前配置信息："
echo "- 插件组: $(grep 'pluginGroup' gradle.properties | cut -d'=' -f2 | xargs)"
echo "- 插件名称: $(grep 'pluginName' gradle.properties | cut -d'=' -f2 | xargs)"
echo "- 插件版本: $(grep 'pluginVersion' gradle.properties | cut -d'=' -f2 | xargs)"
echo "- 最低支持构建号: $(grep 'pluginSinceBuild' gradle.properties | cut -d'=' -f2 | xargs)"
echo "- 平台类型: $(grep 'platformType' gradle.properties | cut -d'=' -f2 | xargs)"
echo "- 平台版本: $(grep 'platformVersion' gradle.properties | cut -d'=' -f2 | xargs)"

echo ""
echo "🔧 构建插件..."
./gradlew clean buildPlugin

if [ $? -eq 0 ]; then
    echo "✅ 插件构建成功！"
else
    echo "❌ 插件构建失败！"
    exit 1
fi

echo ""
echo "🧪 运行测试..."
./gradlew test

if [ $? -eq 0 ]; then
    echo "✅ 测试通过！"
else
    echo "❌ 测试失败！"
    exit 1
fi

echo ""
echo "🔍 验证插件兼容性..."
./gradlew verifyPlugin

if [ $? -eq 0 ]; then
    echo "✅ 插件验证通过！"
    echo ""
    echo "🎉 插件已成功配置为兼容 IntelliJ IDEA 2024.1 及以上版本！"
    echo ""
    echo "📦 构建的插件文件位置："
    find build/distributions -name "*.zip" -type f
    echo ""
    echo "🚀 你可以使用以下命令在 IDE 中测试插件："
    echo "   ./gradlew runIde"
else
    echo "❌ 插件验证失败！请检查配置和代码。"
    exit 1
fi